package mblog.web.controller.api;

import mblog.base.lang.Consts;
import mblog.core.data.Post;
import mblog.core.persist.entity.ResourceAttachPO;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class Media {
    private long id;
    private String title;
    private String content;
    private String tags; // 标签字符串
    private String cover;
    private List<ResourceAttachPO> attaches = new ArrayList<>();

    public Media(Post post) {
        this.id = post.getId();
        this.title = post.getTitle();
        this.content = post.getContent();
        this.tags = post.getTags();
        this.cover = post.getAlbum().getOriginal();
        this.attaches = post.getAttaches();
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public List<ResourceAttachPO> getAttaches() {
        return attaches;
    }

    public void setAttaches(List<ResourceAttachPO> attaches) {
        this.attaches = attaches;
    }

    public String[] getTagsArray() {
        if (StringUtils.isNotBlank(tags)) {
            return tags.split(Consts.SEPARATOR);
        }
        return null;
    }
}
